using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Voodoo.Sauce.Core;
using Voodoo.Sauce.IAP;

namespace Voodoo.Sauce.Debugger
{
	public class IAPDebugScreen : Screen
	{
		[SerializeField]
		private Text lightMessage;

		[SerializeField]
		private Image errorIcon;

		[SerializeField]
		private Text errorMessage;

		private DebugToggleButton premiumToggle;

		private DebugButtonWithInputField restoreButton;

		private IAPDebugManager _manager;

		private void Awake()
		{
			_manager = new IAPDebugManager(this, VoodooSettings.Load());
		}

		private void OnEnable()
		{
			ClearMessages();
			ClearDisplay();
			_manager.OnScreenDisplayed();
		}

		internal void SetVoodooPremiumToggleState(bool isOn)
		{
			premiumToggle.SetValue(isOn);
		}

		internal void EnableRestoreButton(bool active)
		{
			restoreButton.gameObject.SetActive(active);
		}

		internal void CreateProductsButtons(List<IAPDebugProduct> products)
		{
			if (products == null)
			{
				return;
			}
			foreach (IAPDebugProduct product in products)
			{
				WidgetUtility.InstanceOf<IAPProductWidget>(base.Parent).Refresh(product);
			}
		}

		private void ClearMessages()
		{
			errorIcon.gameObject.SetActive(value: false);
			errorMessage.gameObject.SetActive(value: false);
			lightMessage.gameObject.SetActive(value: false);
		}

		internal void DisplayLightMessage(string message)
		{
			ClearMessages();
			lightMessage.gameObject.SetActive(value: true);
			lightMessage.text = message;
		}

		internal void DisplayErrorMessage(string message)
		{
			ClearMessages();
			errorIcon.gameObject.SetActive(value: true);
			errorMessage.gameObject.SetActive(value: true);
			errorMessage.text = message;
		}

		private void OnRestorePurchasesSuccess(RestorePurchasesResult result)
		{
			Debugger.DisplayPopup("Success!", $"Restore purchases successful!: RestorePurchasesResult: {result}");
		}
	}
}
